/***************************************************************************
 *   Copyright (C) 2008 by Goliash   *
 *   goliash@goliash.net   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

 #ifndef MAINWINDOW_H
 #define MAINWINDOW_H

 #include <QtSql>
 #include <QtGui>
 #include "ui_mainwindow.h"
 //#include "ui_add_medium.h"
 #include "add_medium.h"
 #include "medium.h"
 #include "scan_thread.h"
 #include "info_dialog.h"
 #include "db_dialog.h"
 #include "search_dialog.h"
 #include "picture.h"
 #include "audio.h"
 #include "file.h"
 #include "preferencesdialog.h"

const QString DISKMUSTER_VERSION = "0.6.4";

 class MainWindow : public QMainWindow
 {
     Q_OBJECT

 public:

	MainWindow(QMainWindow *parent = 0);	
	void setTableView();
	void updateTableView(int parent, bool path);
	void setTreeView();
	void updateTreeView();
	QSqlDatabase getDb();
	void setMediumToDelete(int id_medium);
	int getMediumToDelete();
	void showData();
	void closeDb();
	void newDb(QString fileName);
	void openDb(QString fileName);
	void showFolder(int id, int id_medium);
	int getSelectedMediumId();
	void updatePath(int in_root, int flag);

	void setActiveDetailDock(QString location);

 signals:
	void itemActivated(const QString &item);

 public slots:
	// file
	void on_actionNew_database_activated();
	void on_actionOpen_database_activated();
	void on_actionSave_activated();
	void on_actionClose_database_activated();

	void on_actionAdd_medium_activated();
	void on_actionFind_activated();
	void deleteMedium();
	void infoMedium();
	void renameMedium();
	void exportMedium();

	// edit
	void on_actionPreferences_activated();

	// browse data
	void changeDetail(QModelIndex index);
	void changeMedium(QModelIndex index);
	void changeFolder(QModelIndex index);
	void goToParentFolder();
	void sortTableView(int section);
	
	// window menu
	void on_actionMove_Detail_Dock_activated();
	void on_actionShow_dock_Details_activated();
	void on_actionShow_dock_Media_activated();
	void on_actionShow_dock_Data_activated();
	void on_dockDetail_visibilityChanged(bool visible);
	void on_dockDetail2_visibilityChanged(bool visible);
	void on_dockMedia_visibilityChanged(bool visible);
	void on_dockData_visibilityChanged(bool visible);

	// help menu
	void on_actionAbout_activated();
	void on_actionAbout_Qt_activated();

	// context
	void showContextMenu(const QPoint &pos);
 private:
	Ui::MainWindow ui;
	QSqlDatabase db;
	//Ui::add_medium_dialog amd;

	//QSqlQueryModel *model_tree;
	QStandardItemModel *model_tree;
	//QSqlQueryModel *model_detail;
	//QSqlQueryModel *model;
	QStandardItemModel *model;
	//MySqlTableModel *model;
	int currentMedium;
	int current_detail;
	int currentFolder;
	QString curFolderName;
	QString currentOrder;
	bool ascOrder;
	int mediumToDelete;

	Preferences * prefs;	

	QString currentDockDetail;
	QDockWidget *activeDockDetail;
	QLabel *activeTextInfo;
	QLabel *activeThumbnail;

	void readSettings();
	void writeSettings();

protected:
	void contextMenuEvent(QContextMenuEvent *event);
	void closeEvent(QCloseEvent *event);
};

 #endif
